<template>
	<view class="content">
		<!-- 导航栏 -->
		<u-sticky class="test" style="background-color: #e8fdf6;">
			<view class="container" :style="[{'top': customBarH + 'rpx'}]">
				<image class="topTitle" src="../../static/topTitle.png" width="128"></image>
				<view class="searchBar">
					<u-search animation="true" placeholder="最新早报" :showAction="false" inputAlign="left" height="30"
						bgColor="#faffff" searchIconColor="#888888" color="#111111" placeholderColor="#888888"
						margin="3px 0 0 0 " @search="searchClick" v-model="searchTitle">
					</u-search>
				</view>
			</view>
			<view class="top-background" :style="[{'height': top_backgroundH + 'rpx'}]">
			</view>
		</u-sticky>
		<view class="main">
			<view class="u-demo-block" style="display: unset;">
				<u-swiper :list="broadcastList" keyName="image" :autoplay="true" showTitle circular radius="0"
					height="170" bgColor="#ffffff" indicator indicatorMode="dot" indicatorStyle="right: 20px;"
					@click="swiperClick">
				</u-swiper>
			</view>

			<!-- 文章列表 -->
			<ul>
				<li v-for="i in postList" class="postli" @tap="liTap(i.id)"
					style="height: auto;border-bottom:1px solid #edeef2;padding: 10px 14px;">
					<view class="post-view" style="display: grid;grid-template-columns: 7fr 4fr;grid-gap: 10px;">
						<view class="post-left" style="display: grid;grid-template-rows: 3fr 1fr;">
							<view class="post-left-top">
								<p>{{i.title}}</p>
							</view>
							<view class="post-left-bottom"
								style="display: grid;grid-template-columns: auto 2fr;grid-gap: 8px;">
								<view class="post-author" style="max-width: 130px;">
									<p>{{i.author}}</p>
								</view>
								<view class="post-time">
									<p>{{i.time}}</p>
								</view>
							</view>
						</view>
						<view class="post-right"
							style="place-items:center end;display: grid;grid-template-rows: 10fr 2fr">
							<u--image :showLoading="true" :src="i.coverpic" width="130px" height="80px" radius="4">
							</u--image>
							<u-album :urls="i.coverpic"></u-album>
							<view class="readCount" style="margin-right: 5px;display: flex;">
								<u-icon width="18px" height="18px"
									name="https://notewk-1304925042.cos.ap-guangzhou.myqcloud.com/notewk/eye.png"
									color="#aeaeae" size="18"></u-icon>
								<p style="margin-left: 3px;margin-right: 10px;">{{i.readCount}}</p>
								<u-icon width="16px" height="14px"
									name="https://notewk-1304925042.cos.ap-guangzhou.myqcloud.com/notewk/star.png"
									color="#aeaeae" size="18"></u-icon>
								<p style="margin-left: 3px;">{{i.star}}</p>
							</view>
						</view>
					</view>
				</li>
			</ul>
			<u-back-top :scroll-top="scrollTop"
				icon="https://notewk-1304925042.cos.ap-guangzhou.myqcloud.com/notewk/上箭头.png" bottom="50">
			</u-back-top>
		</view>
	</view>
</template>

<script>
	import {
		getBroadcastList,
		getPostList,
		searchApi
	} from "@/utils/api.js"
	export default {
		data() {
			return {
				title: 'Hello',
				scrollTop: 0, //回到顶部
				customBarH: 0,
				offsetTopH: 0,
				top_backgroundH: 0,
				broadcastList: [],
				postList: [],
				readCount: 13,
				star: 13,
				searchTitle: ''
			}
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		onLoad() {
			getBroadcastList().then((res) => {
				console.log(res)
				this.broadcastList = res
			})
			getPostList().then((res) => {
				console.log(res)
				this.postList = res
			})
		},
		methods: {
			searchClick() {
				uni.navigateTo({
					url: '/pages/search/search?title=' + this.searchTitle,
				})
				// searchApi(this.searchTitle).then((res) => {
				// 	console.log(res)
				// })
			},
			liTap(id) {
				console.log(id)
				uni.navigateTo({
					url: '/pages/content/content?id=' + id,
				})
			},
			swiperClick(index) {
				console.log(this.broadcastList[index])
				uni.navigateTo({
					url: '/pages/content/content?id=' + this.broadcastList[index].article,
				})
			},
			clickToCopy() { // 复制功能
				console.log("111")
				wx.setClipboardData({
					data: '要复制文本，可用变量表示',
					success: function(res) {
						wx.showToast({
							title: '复制成功',
							icon: "none",
							mask: "true" //是否设置点击蒙版，防止点击穿透
						})
					}
				})
			}
		},
		created() {
			console.log(uni.getMenuButtonBoundingClientRect())
			this.customBarH += uni.getSystemInfoSync().statusBarHeight
			this.customBarH += uni.getMenuButtonBoundingClientRect().height
			// this.customBarH += uni.getMenuButtonBoundingClientRect().top
			// this.customBarH += uni.getMenuButtonBoundingClientRect().bottom
			this.customBarH += 20
			this.top_backgroundH = this.customBarH + uni.getMenuButtonBoundingClientRect().bottom
			this.offsetTopH += uni.getMenuButtonBoundingClientRect().bottom //搜索栏位置
			console.log(this.customBarH)
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.container {
		width: 750rpx;
		left: 50%;
		z-index: 2; //使之浮在上层
		position: absolute; //使之浮在上层
		transform: translate(-50%);
		overflow: 0;
		display: grid;
		grid-template-columns: 3fr auto;
	}

	.topTitle {
		width: 48px;
		height: 41px;
		margin-left: 35rpx;
		margin-top: -4px; //微信开发者工具尺寸
	}

	.searchBar {
		width: 50vw;
		margin-right: 140px;
		margin-left: 20px;
		border-radius: 30px
	}

	.u-search {
		height: 28px;
	}

	.u-icon__icon {
		left: 0;
	}

	.top-background {
		z-index: 1;
		background-color: #e8fdf6;
		width: 100vw;
		margin-top: -1rpx
	}

	.main {
		z-index: 0;
		width: 100vw;
	}

	.function-view {
		padding: 10rpx 0;
		width: 100%;
		display: grid;
		grid-template-columns: repeat(5, 1fr);
		grid-column-gap: 12px;
		grid-row-gap: 10px;
	}

	.function-view-item {
		display: grid;
		grid-template-rows: 7fr 2fr;
	}

	.function-view-item-pic {
		position: relative;
	}

	.function-view-item-text {}

	.function-view-item-img {
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		width: 105rpx;
		height: 105rpx;
	}

	.post-left-bottom {
		margin-top: 7px;
	}

	.post-left-top p {
		overflow: hidden;
		display: -webkit-box;
		-webkit-line-clamp: 3;
		-webkit-box-orient: vertical;
		font-size: 18px;
		color: #353b48;
		margin-top: 1px;
		letter-spacing: 1px;
		line-height: 1.5;
	}

	.post-author p {
		font-size: 13px;
		color: #999999;
		overflow: hidden;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
	}

	.post-time p {
		font-size: 13px;
		color: #999999;
		overflow: hidden;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
	}

	.readCount p {
		font-size: 13px;
		color: #aeaeae;
	}

	.u-back-top {
		background-color: #74BE9B !important;
	}
</style>
